namespace wxb
{
  template<class T>
    struct Less
    {
      bool operator() (T&x,T&y)
      {
        return x<y;
      }
    }

  template<class T> 
   struct Greater
   {
     bool operator() (T&x,T&y)
     {
       return x>y;
     }
   }
  template<class T,class Container=vector<T>,class Compare =less<T> >
  class priority_queue
  {
      void JustDown()
      {
         size_t parent=0;
         size_t child=parent*2+1;
         while(child<c.size()-1)
         {
           if(child+1<c.size()-1&&c[child]<c[child+1])
           {
             child++;
           }
           if(c[child]>c[parent])
           {
             swap(c[child],c[parent]);
           }
           else
           {
              break;
           }
           parent=child;
           child=parent*2+1;
         }

      }
      void JustUp(size_t child)
      {
           
          while(child>0)
          {
           size_t parent=(child-1)/2;
           
           if(c[child]>c[parent])
           {
             swap(c[child],c[parent]);
           }
           else
           {
             break;
           }
           child=parent;

          }


      }
      public:
          priority_queue()
          {

          }

          template<class InputIterator>
          priority_queue(InputIterator first,InputIterator end)//迭代区间初始化
          {
            while(first!=end)
            {
              c.push_back(*first);
              first++;
            }

          }
         void Print()
         {
           for(auto cou:c)
           {
             cout<<cou<<' ';
           }
           cout<<endl;
         }
        void push(const T & x)
        {
          c.push_back(x);
          size_t child=c.size()-1;
          JustUp(child);
        }

        void pop()
        {
          
          swap(c[0],c[c.size()-1]);//交换堆顶的数据与末尾的数
          c.pop_back();

          if(c.size()!=0)
          JustDown();
          
        }
        size_t size()const{
          return c.size();
        }
        bool empty()const 
        {
          return c.empty();
        }
        const T&top()const 
          {
            return c.front();
          }
      private:
       Container c;
      Container com;
  };
};
